/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SavedPlaylistDialog.java
 *
 * Created on Nov 18, 2009, 6:00:22 PM
 */

package com.bff.slimserver.musicjukebox.ui.components.savedplaylist;

import com.bff.mpd.musicjukebox.ui.components.MusicJDialog;
import com.bff.slimserver.musicjukebox.ui.SavePlaylistDialog;
import com.bff.bjj.ui.component.BJJPanel;
import com.bff.bjj.utils.Utils;
import org.bff.slimserver.musicobjects.SlimSavedPlaylist;

/**
 *
 * @author Bill
 */
public class SavedPlaylistDialog extends MusicJDialog {

    private SlimSavedPlaylist selectedPlaylist;

    /** Creates new form SavedPlaylistDialog */
    public SavedPlaylistDialog(java.awt.Frame parent) {
        super(parent);
        initComponents();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new BJJPanel();
        btnSelect = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        btnCreateNew = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        playlistList = new SavedPlaylistList();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Select Saved Playlist");
        setMinimumSize(new java.awt.Dimension(300, 400));

        btnSelect.setText("Select");
        btnSelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSelectActionPerformed(evt);
            }
        });
        jPanel1.add(btnSelect);

        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });
        jPanel1.add(btnCancel);

        btnCreateNew.setText("Create New");
        btnCreateNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCreateNewActionPerformed(evt);
            }
        });
        jPanel1.add(btnCreateNew);

        getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);

        jScrollPane1.setViewportView(playlistList);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectActionPerformed
        setSelectedPlaylist(getPlaylistList().getSelectedPlaylist());
        this.dispose();
    }//GEN-LAST:event_btnSelectActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
       setSelectedPlaylist(null);
       this.dispose();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void btnCreateNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCreateNewActionPerformed
        new SavePlaylistDialog(Utils.getParentComponent(this), true).setVisible(true);
        getPlaylistList().refresh();
    }//GEN-LAST:event_btnCreateNewActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnCreateNew;
    private javax.swing.JButton btnSelect;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList playlistList;
    // End of variables declaration//GEN-END:variables

    private SavedPlaylistList getPlaylistList() {
        return (SavedPlaylistList) playlistList;
    }

    /**
     * @return the selectedPlaylist
     */
    public SlimSavedPlaylist getSelectedPlaylist() {
        return selectedPlaylist;
    }

    /**
     * @param selectedPlaylist the selectedPlaylist to set
     */
    private void setSelectedPlaylist(SlimSavedPlaylist selectedList) {
        this.selectedPlaylist = selectedList;
    }
}
